<!-- 当前状态-Echarts -->
<template>
<div class="time">
    <span>{{nowTime.year}}</span>
    <span class="q-ml-md">{{nowTime.week}}</span>
    <span class="q-ml-md">{{nowTime.time}}</span>
</div>
</template>

<script>
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'Time',
  components: {
},
  data() {
    return {
      nowTime:{
        year:'',
        week:'',
        time:''
      },
    }
  },
  created() {
      this.nowTimes();
  },
  activated() {
  },
  beforeUnmount() {
  },
  deactivated() {
  },
  methods: {
      
    //显示当前时间（年月日时分秒）
    timeFormate() {
        let timeStamp = new Date();
      let year = new Date(timeStamp).getFullYear();
      let month =new Date(timeStamp).getMonth() + 1 < 10? "0" + (new Date(timeStamp).getMonth() + 1): new Date(timeStamp).getMonth() + 1;
      let date =new Date(timeStamp).getDate() < 10? "0" + new Date(timeStamp).getDate(): new Date(timeStamp).getDate();
      let hh =new Date(timeStamp).getHours() < 10? "0" + new Date(timeStamp).getHours(): new Date(timeStamp).getHours();
      let mm =new Date(timeStamp).getMinutes() < 10? "0" + new Date(timeStamp).getMinutes(): new Date(timeStamp).getMinutes();
      let ss =new Date(timeStamp).getSeconds() < 10? "0" + new Date(timeStamp).getSeconds(): new Date(timeStamp).getSeconds();
      let week = new Date(timeStamp).getDay();
      let weeks = ["日","一","二","三","四","五","六"];
      
      this.nowTime.week = "星期" + weeks[week];
      this.nowTime.year = year + '-' + month + '-' + date;
      this.nowTime.time = hh + ":" + mm;
    },
    nowTimes(){
      setInterval(this.timeFormate,1000);
    },
  },
  beforeUnmount() {
    if (this.timeFormate) {
      clearInterval(this.timeFormate); // 在Vue实例销毁前，清除时间定时器
    }
  }

})
</script>

<style lang="scss" scoped>
</style>

